package exercises;

/**
 * @author zerorain
 **/
import java.util.*;
//连续最大和  简单的思路题 每次和之前的最大和作比较 输出最大即可
public class ex9 {
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] arr = new int [n];
        for(int i = 0 ; i < arr.length ; i ++){
            arr[i] = sc.nextInt();
        }
        int ret = arr[0];
        int temp = arr[0];
        for(int i = 1 ; i < n ; i++){
            temp = Math.max(temp + arr[i],arr[i]);
            if(temp > ret ){
                ret = temp;
            }
        }
        System.out.print(ret);
    }
}